<?php

namespace App\Models;


use EloquentFilter\Filterable;
use Illuminate\Notifications\Notifiable;

class Menus extends BaseModel
{
    use Notifiable, Filterable;

    /**
     * @var string
     */
    protected $table = 'menus';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'icon',
        'link',
        'status',
        'weight',
        'parent_id',
        'key'
    ];

    /**
     * 上级
     * @return mixed
     */
    public function parent()
    {
        return $this->belongsTo(Menus::class);
    }

    /**
     * 获取子集
     * @return mixed
     */
    public function children()
    {
        return $this->hasMany(Menus::class, 'parent_id', 'id')->orderBy('weight', 'DESC');
    }
}
